#include "IOParams.h"

IOParams::IOParams(int argc, char **argv){
//try{
  this->N = atoi(argv[1]); //40
  this->U0 = atof(argv[2]);
//  this->T1 = atof(argv[3]);
  string auxStr(argv[3]); // FIXME: Find a better way to do the initialization.
  
  this->strSuffix=""+auxStr;
  
  this->prmfilename="InputParams.prm";
  
  string strN(argv[1]);
  string strU0(argv[2]);
  string strT1("");
//  string strT1(argv[3]);
//  string strT2(argv[XXXX]);
  
  
	    
//  this->sqrtT1=sqrt(T1);
//  this->sqrtT2=sqrt(T2);
	// TODO: Read InputParams.prm file
	ifstream paramFile;
	paramFile.open(this->prmfilename.c_str());
	
  string line;
	while( getline(paramFile,line) ){
	  stringstream linestream(line);
	 
	  string key;
	  getline(linestream,key,'=');
  
    if (key=="eps"){
	    getline(linestream,key,'=');
	    cout<<key<<endl;
	    this->eps = atoi(key.c_str());
	    
	  }else if(key=="gamma1"){
	  	getline(linestream,key,'=');
	    cout<<key<<endl;
		  this->gamma1=atof(key.c_str());
		  
	  }else if(key=="gamma2"){
	  	getline(linestream,key,'=');
	    cout<<key<<endl;
		  this->gamma2=atof(key.c_str());
		  
	  }else if (key=="total_time"){
	    getline(linestream,key,'=');
	    cout<<key<<endl;
	    this->total_time = atoi(key.c_str());
	    
	  }else if(key=="timeDim"){
		  getline(linestream,key,'=');
	    cout<<key<<endl;
	  	this->timeDim= atoi(key.c_str()); //40000;
	  	
	  }else if(key=="dt"){
	  	getline(linestream,key,'=');
	    cout<<key<<endl;
		  this->dt=atof(key.c_str());
		  
	  }else if(key=="T1"){
	  	getline(linestream,key,'=');
	  	strT1=key;
	    cout<<strT1<<endl;
		  this->T1=atof(key.c_str());
	  }else if(key=="T2"){
	  	getline(linestream,key,'=');
	    cout<<key<<endl;
		  this->T2=atof(key.c_str());
	  }
	}
  paramFile.close();

  
  
  this->basename="N_"+strN+"__U0_"+strU0+"__T1_"+strT1+"__id_"+strSuffix;

  this->inifilename =this->basename+".ini";
  this->outfilename =this->basename+".dat";
  this->outfilename2=this->basename+".end";
  cout<<this->outfilename<<endl;

  this->ttime = 0;

  if (this->total_time > this->timeDim){
  	this->taux = this->total_time/this->timeDim;
  }else{
  	this->taux = 1;
  }

  this->dt2 = dt*dt;
  
  
  

//  }catch (exception& e){
//    cout << "Standard exception: " << e.what() << endl;
//  }
}

IOParams::~IOParams(){

}
